﻿using System;

class SolveTasks
{
    static void Main()
    {
        ShowStartScreenWithMenus();    
    }

    private static void ShowStartScreenWithMenus()
    {
        Console.WriteLine("Press \"1\" to reverse the digits of a number;");
        Console.WriteLine("Press \"2\" to calculate average sum of integers;");
        Console.WriteLine("Press \"3\" to solve linear equation (a*x+b=0);");

        int choice = int.Parse(Console.ReadLine());

        switch (choice)
        {
            case 1:
                ReverseDigits();
                break;
            case 2:
                CalculateAverage();
                break;
            case 3:
                SolveEquation();
                break;
        }
    }

    private static void ReverseDigits()
    {
        Console.WriteLine("Enter a number:");
        decimal number = decimal.Parse(Console.ReadLine());

        if (number < 0)
        {
            Console.WriteLine("The number must be positive!");
            ReverseDigits();
            return;
        }

        char[] array = number.ToString().ToCharArray();
        Array.Reverse(array);
        decimal reversed = decimal.Parse(new string(array));
        Console.WriteLine(reversed);
    }

    private static void CalculateAverage()
    {
        Console.WriteLine("How many number you will enter:");
        int numbers = int.Parse(Console.ReadLine());
        if (numbers == 0)
        {
            Console.WriteLine("The sequence cannot be empty!");
            CalculateAverage();
            return;
        }
        int sum = 0;

        for (int i = 0; i < numbers; i++)
        {
            sum += int.Parse(Console.ReadLine());
        }
        Console.WriteLine("THe average of those numbers is: {0}", sum / (float)numbers);
    }

    private static void SolveEquation()
    {
        Console.WriteLine("Enter \"a\" coefficient:");
        int a = int.Parse(Console.ReadLine());
        if (a==0)
        {
            Console.WriteLine("\"a\" cannot be 0!");
            SolveEquation();
            return;
        }

        Console.WriteLine("Enter \"b\" coefficient:");
        int b = int.Parse(Console.ReadLine());

        Console.WriteLine("x={0}", -b / (float)a);
    }
}